package com.dc.business.datacollectbusiness.model;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@NoArgsConstructor
@AllArgsConstructor
@Data
public class Result<T>{
    private int code;//业务状态码，0-成功，1-失败
    private String msg;//提示信息
    private Object data;//响应数据
    private int sum;//分页查询总数(默认为0)

    //快速返回操作成功响应结果（带响应数据）
    public static <E> Result<E> success(E data) {
        return new Result<>(0,"操作成功",data,0);
    }

    //快速返回操作成功响应结果（带响应数据）分页使用
    public static <E> Result<E> successfy(E data,int sum) {
        return new Result<>(0,"操作成功",data,sum);
    }

    //返回操作不带结果
    public static Result success(){
        return new Result(0,"操作成功",null,0);
    }

    //错误提示返回
    public static Result error(String msg){
        return new Result(1,msg,null,0);
    }

    public static <E> Result<E> error(E data){
        return new Result<>(1,"操作失败",data,0);
    }
}
